package com.ly.lypopupwindowdemo.animation;


import android.animation.TypeEvaluator;

/**
 * Created by liying on 2017/9/22.
 */

public class PointSinEvaluator implements TypeEvaluator {

    /**
     *
     * @param fraction  当前动画完成的百分比
     * @param startValue 动画的初始值
     * @param endValue   动画的结束值
     * @return
     */
    @Override
    public Object evaluate(float fraction, Object startValue, Object endValue) {
        Point startPoint = (Point) startValue;
        Point endPoint = (Point) endValue;


        //x的值随着fraction不断变化，并最终达到结束值
        //y的值就是当前x值对应的sin(x)值
        //然后x和y产生一个新的point对象返回

//        float x = startPoint.getX() + fraction * (endPoint.getX() - startPoint.getX());
//        float y = (float) (Math.sin(x * Math.PI / 180) * 100) + endPoint.getY() / 2;
//        Point point = new Point(x, y);

        /**
         * 用结束值减去初始值，算出它们之间的差值，然后乘以fraction这个系数，再加上初始值，那么就得到当前动画的值了。
         */
        float x = startPoint.getX()+fraction*(endPoint.getX()-startPoint.getX());
        float y = startPoint.getY()+fraction*(endPoint.getY()-startPoint.getY());
        Point point = new Point(x,y);
        return point;
    }
}
